package cnpm02.j2ee.group3.model;

import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;

@Entity
@Table(name = "FLIGHT", uniqueConstraints = @UniqueConstraint(columnNames = {
                "FlightLineId", "DepartDate"}))
@AttributeOverride(name = "id", column = @Column(name = "FlightId"))
public class Flight extends AbstractEntity {
	private static final long serialVersionUID = 1L;
	@ManyToOne(cascade = {PERSIST, MERGE})
	@JoinColumn(name = "FlightLineId", nullable = false)
	@NotNull
	private FlightLine flightLine;
	
	@ManyToOne(cascade = {PERSIST, MERGE})
	@JoinColumn(name = "PlaneId", nullable = false)
	@NotNull
	private Plane plane;
	
	@NotNull
	@Column(name = "DepartDate", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date departDate;
	
	@NotNull
	@Column(name = "ArriveDate", nullable = true)
	@Temporal(TemporalType.TIMESTAMP)
	private Date arriveDate;
	
	@NotNull
	@Column(name = "Status", nullable = false, columnDefinition = "varchar(10) default 'normal'")
	@Length(max = 10)
	private String status;
	
	public Flight(){
		super();
		
		status = "normal";
	}
	
	public Flight(Plane myPlane, FlightLine myFlightLine, Date departDate, Date arriveDate){
		super();
		plane = myPlane;
		flightLine = myFlightLine;
		this.departDate = departDate;
		this.arriveDate = arriveDate;
		
		status = "normal";
	}
	
	public void setFlightLine(FlightLine flightLine) {
		this.flightLine = flightLine;
	}
	
	public FlightLine getFlightLine() {
		return flightLine;
	}
	
	public void setPlane(Plane plane) {
		this.plane = plane;
	}
	
	public Plane getPlane() {
		return plane;
	}

	public void setDepartDate(Date departDate) {
		this.departDate = departDate;
	}

	public Date getDepartDate() {
		return departDate;
	}

	public void setArriveDate(Date arriveDate) {
		this.arriveDate = arriveDate;
	}

	public Date getArriveDate() {
		return arriveDate;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getStatus() {
		return status;
	}
}
